import re

from django.http import HttpResponseBadRequest
from django.shortcuts import render

# Create your views here.
from django.views import View

from apps.category.models import Article
from apps.index.models import Today, EverydaySentence,Notification
from django.db import DatabaseError

from apps.index.utils import hanhan


class IndexView(View):
    """this is index """
    def get(self,request):


        context=hanhan()

        user=request.user
        if user is None:
            context['user']=False
        else:
            context['user']=user

        aritcles=Article.objects.all().order_by('-date')
        context['articles']=aritcles

        return render(request,'base_index.html',context);


class Search(View):
    def post(self,request):
        value=request.POST.get('keyword')
        articles=Article.objects.filter(title__contains=value)



        context=hanhan()

        context['articles']=articles


        return render(request,'search.html',context=context)
